import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:xin_he/routes/xin_he_routes.dart';
import 'package:xin_he/utils/xh_styles.dart';

import '../page/login/xin_he_login/xin_he_login_view.dart';
import '../utils/xin_he_user_data.dart';

//normal通用-所有页面适用的规则
class NormalAuth extends GetMiddleware {

  /// 状态栏为黑色页面
  List<String> darkRoutes = [];

  @override
  RouteSettings? redirect(String? route) {
    // TODO: implement redirect
    print('打开页面$route');
    setStyle(route);

    // if(!kdUserData.appLoginState.value){
    //   return const RouteSettings(name: AppRoutes.login);
    // }
    return super.redirect(route);
  }

  @override
  void onPageDispose() {
    // TODO: implement onPageDispose
    print('页面关闭');
    setStyle(Get.previousRoute);
    super.onPageDispose();
  }

  void setStyle(String? route) {
    if (route == XinHeRoutes.root) {
      XinHeStyle.setSystemBackgroundStyle(isLight: false);
    } else {
      if (this.darkRoutes.contains(route)) {
        //设置系统字状态栏字体为黑色
        XinHeStyle.setSystemBackgroundStyle(isLight: false);
      }else {
        //设置系统字状态栏字体为白色
        XinHeStyle.setSystemBackgroundStyle(isLight: false);
      }
    }
  }
}



///登录拦截
class LoginMiddleware extends GetMiddleware {
  @override
  int?   priority;

  LoginMiddleware({required this.priority});

  @override
  RouteSettings? redirect(String? route) {
    // if(!xinHeUserData.appLoginState.value){
    //   Get.bottomSheet(XinHeLoginPage(),persistent: false,isScrollControlled: true);
    // }

    return super.redirect(route);
  }
}